<template>
	<view class="box">
		<block v-for="(item,index) in LeaveDateList" :key="index">
			<my-card :item="item"></my-card>
		</block>
	</view>
</template>

<script>
	import myCard from './my-card.vue'
	import {apigetAllLeaveList,apigetLeaveList} from '@/common/api.js'
	export default {
		name:"leave-records",
		data() {
			return {
				LeaveDateList:[],
				options: [{
                text: '取消',
                style: {
                    backgroundColor: '#007aff'
                }
            }, {
                text: '确认',
                style: {
                    backgroundColor: '#dd524d'
                }
            }]
			}
		},
		components:{
			myCard
		},
		onLoad(){
			this.getLeaveRecord()
		},
		methods: {
			change_time(time){
				let date=new Date(time)
				let year=date.getFullYear()
				let month=date.getMonth()+1
				let days=date.getDate()
				let hour=date.getHours()
				let min=date.getMinutes()
				let second=date.getSeconds()
				days=days<10?"0"+days:days
				month=month<10?`0${month}`:month
				hour=hour<10?'0'+hour:hour
				min=min<10?'0'+min:min
				second=second<10?'0'+second:second
				return `${year}年${month}月${days}日 ${hour}:${min}`
			},
			getLeaveRecord(){
				let LeaveDate={					
					pageSize:'20',
					limit:'1'
				}
				apigetLeaveList(LeaveDate).then(res=>{					
					this.LeaveDateList=res.data.data.map(item=>{
						item.start_time=this.change_time(item.start_time)
						item.end_time=this.change_time(item.end_time)
						return item
					})
					//console.log(JSON.stringify(this.LeaveDateList))
				}).catch(err=>{
					console.log(JSON.stringify(err))
				})
			},
			getAllLeaveRecord(){
				let LeaveDate={
					start_time:'',
					end_time:'',
					department:'',
					applicant:'',
					status:'',
					leave_category:''
				}
				apigetAllLeaveList(LeaveDate).then(res=>{
					console.log(JSON.stringify(res))
				}).catch(err=>{
					console.log(JSON.stringify(err))
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		width: 100%;
		height: 100%;
	}
</style>
